/**
 *
 */
package de.cbf.cam.dsa.rcp.model.entities.items;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import de.cbf.cam.dsa.rcp.model.entities.ProfessionDSA;
import de.cbf.util.uuidheader.entities.UUIDHeader;
import de.cbf.util.uuidheader.exceptions.EntityMergeException;

/**
 * @author salter
 *
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ProfessionItemDSA extends ProfessionDSA {
	@XmlElementWrapper(name="professionItems")
	@XmlElement(name="item")
	protected List<ItemForProfession> professionItems;

	@Override
	protected void init() {
		super.init();
		professionItems  = new ArrayList<ItemForProfession>();
	}

	@Override
	protected void doMergeDataFrom(UUIDHeader entity, boolean i_am_older)
			throws EntityMergeException {
		super.doMergeDataFrom(entity, i_am_older);
		if (entity instanceof ProfessionItemDSA) {
			ProfessionItemDSA other = (ProfessionItemDSA) entity;
			if(i_am_older){
				this.professionItems.clear();
				this.professionItems.addAll(other.professionItems);
			}
		}else{
			String mergeEntityClass = entity == null? "null":entity.getClass().getName();
			String errorMsg ="EntityToMerge "+mergeEntityClass+" does not fit class:"+this.getClass().getName();
			throw new EntityMergeException(errorMsg);
		}
	}

	public List<ItemForProfession> getProfessionItems() {
		return professionItems;
	}

	public void setProfessionItems(List<ItemForProfession> professionItems) {
		this.professionItems = professionItems;
	}
}
